<div class="page-header">
    <h1><?php echo $this->titulo;?></h1>
</div>

<div class="table-responsive">
   
    <form id="form_edt" method="post" action="" enctype="application/x-www-form-urlencoded" >
    <?php
    //echo $this->form;

    $url = $this->urlbase.'/'.$this->modulo.'/'.$this->controller;

    $el = new Zend_Form_Element_Hidden('PER_ID',array('disableLoadDefaultDecorators' =>true));
    $el->addDecorators(array(array('ViewHelper'),array('Errors')))
        ->setValue($this->obj['PER_ID'])
        ->addFilter('Int');
    echo $el;

    $nome = new Zend_Form_Element_Text('PER_NOM');
    $nome->setLabel('Nome')
    ->setValue($this->obj['PER_NOM'])
    ->setRequired(true)
    ->addFilter('StripTags')
    ->addFilter('StringTrim')
    ->addValidator('NotEmpty');
    $nome->setAttrib('class', 'form-control');
    $nome->setAttrib('required', 'required');
    echo $nome;
    
    ?> 
    <br>
    <dd>
        <div class="table-responsive">
            <table id="tlist" class="table table-striped table-hover">
                <tr>
                    <th width="300">Módulo</th>
                    <th width="50">Painel</th>
                    <th width="20">Permissão</th>
                    <th width="20">Adicionar</th>
                    <th width="20">Editar</th>
                    <th width="20">Deletar</th>
                </tr>

        <?php

        //$obj = new Painel_Model_DbTable_Modulos();
        //$row = $obj->fetchAll($obj->select()->order('MOD_NOM ASC'));  
        $query = 'SELECT SQL_CACHE * FROM MODULOS ORDER BY MOD_TPOSIS ASC, MOD_NOM ASC';
        $row = $this->db->fetchAll($query);
        $arr = array();

        foreach($row as $key => $r)
        {            
            //$obj_prm = new Painel_Model_DbTable_PermissaoHasModulo();
            //$row_prm = $obj_prm->fetchAll('PER_ID = '.$this->PER_ID.' and MOD_ID = '.$r['MOD_ID'])->toArray();
            $query = 'SELECT SQL_CACHE * FROM PERMISSAO_HAS_MODULO WHERE PER_ID = "'.$this->obj['PER_ID'].'" and MOD_ID = '.$r['MOD_ID'];
            $row_prm = $this->db->fetchAll($query);
            $chk_mod = $chk_add = $chk_edt = $chk_del = '';
            foreach($row_prm as $r_prm){
               $chk_mod = 'checked="checked"';
               if($r_prm['MOD_ADD'] == 1) $chk_add = 'checked="checked"';
               if($r_prm['MOD_EDT'] == 1) $chk_edt = 'checked="checked"';
               if($r_prm['MOD_DEL'] == 1) $chk_del = 'checked="checked"';
            }
        ?> 
                <tr>
                    <td style="color:#000;"><?php echo $r['MOD_NOM']; ?></td>
                    <td><?php echo dominio::getTpoSistemas($r['MOD_TPOSIS']); ?></td>
                    <td style="text-align: center;"><input type="checkbox" <?php echo $chk_mod;?> value="<?php echo $r['MOD_ID']; ?>" name="MOD_ID[]"></td>
                    <td style="text-align: center;"><input type="checkbox" <?php echo $chk_add;?> value="1" name="MOD_ADD[<?php echo $r['MOD_ID']; ?>]"></td>
                    <td style="text-align: center;"><input type="checkbox" <?php echo $chk_edt;?> value="1" name="MOD_EDT[<?php echo $r['MOD_ID']; ?>]"></td>
                    <td style="text-align: center;"><input type="checkbox" <?php echo $chk_del;?> value="1" name="MOD_DEL[<?php echo $r['MOD_ID']; ?>]"></td>
                </tr>
        <?php
        }

        ?> 
            </table>
        </div>  
    </dd>
    <?php

    $el = new Zend_Form_Element_Checkbox('PER_STA',array('checked'=>'checked'));
    $el->setValue($this->obj['PER_STA']);
    echo $el->setLabel('Status');
    
    $el = new Zend_Form_Element('br',array( 'helper'=>'formNote', 'value'=>'&nbsp;' ));
    echo ($el);
    
    $btn = new Zend_Form_Element_Button('Salvar',array('disableLoadDefaultDecorators' =>true));
    $btn->setDecorators(array(array('Description', array('escape' => false, 'tag' => false))));
    $btn->setDescription('<button type="submit" class="btn btn-lg btn-success"><span class="glyphicon glyphicon-floppy-saved" aria-hidden="true"></span> Salvar</button>');
    echo ($btn);

    $btn = new Zend_Form_Element_Button('Cancelar',array('disableLoadDefaultDecorators' =>true));
    $btn->setDecorators(array(array('Description', array('escape' => false, 'tag' => false))));
    $btn->setDescription('<a href="'.$url.'" class="btn btn-lg btn-danger"><span class="glyphicon glyphicon-floppy-remove" aria-hidden="true"></span> Cancelar</a>');
    echo ($btn);
    

    ?>
    </form>

</div>